package com.restful;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class  RestFulController {
    //@RequestMapping
    //原来样式: http://localhost:8080/toRestFu?a=1&b=2

    //restful风格 http://localhost:8080/toRestFul/1/2
    //get方式  注解
    @GetMapping("/toRestFul/{a}/{b}")      //restful风格注解
    // 前后端参数名不一致时可以用@RequestParam注解("name") 重新设置参数名 加上@RequestParam注解即表示为前端传递过来的参数
    public String toRestFulString(@PathVariable  int a, @PathVariable int b, Model model){
        int res = a+b;
        model.addAttribute("res","get:"+res);
        return "Restful";
    }

    //post 方式
    //问题：restful风格如何用 post方式传参

    @PostMapping("/toRestFul/{a}/{b}")
    public String toRestFulString1(@RequestBody @PathVariable int a, @RequestBody @PathVariable int b, Model model){
        model.addAttribute("res","post:"+(a+b));
        return "Restful";
    }
}
